package com.material.common.entity;

import com.material.common.constant.HttpStatus;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.io.Serializable;

/**
 * @author : ganxinge
 * @date : 2022/3/8 11:10
 */
@ApiModel("响应参数")
public class ResultResponse<T> implements Serializable {

    @ApiModelProperty(value = "状态码",required = true,example = "200")
    private Integer code;
    @ApiModelProperty(value = "消息描述",required = true,example = "操作成功")
    private String message;
    @ApiModelProperty(value = "响应数据",required = true)
    private T data;

    public ResultResponse(){

    }

    public ResultResponse(Integer code, String message){
        this.code = code;
        this.message = message;
    }

    public ResultResponse(Integer code, String message, T data){
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static ResultResponse success(){
        return ResultResponse.success("操作成功");
    }

    public static ResultResponse success(Object data){
        return ResultResponse.success("操作成功",data);
    }

    public static ResultResponse success(String message){
        return ResultResponse.success(message,null);
    }

    public static ResultResponse success(String message, Object data){
        return new ResultResponse(HttpStatus.SUCCESS,message,data);
    }


    public static ResultResponse error(){
        return ResultResponse.error("操作失败");
    }

    public static ResultResponse error(String message){
        return ResultResponse.error(message,null);
    }

    public static ResultResponse error(Integer code, String message){
        return new ResultResponse(code,message);
    }

    public static ResultResponse error(String message, Object data){
        return new ResultResponse(HttpStatus.ERROR,message,data);
    }





    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
